/*
 * Copyright Eduardo Aponte 2013
 * aponteeduardo@gmail.com
 */
#include <eyelink.h>
#include "mex.h"


INT16 _main( char FARTYPE *msg )
{
    return eyelink_read_reply( msg );
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[] = {1,1};
    double *status;
    char FARTYPE *msg;

    /* Verify input arguments. */
    if(nrhs != 0 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 2 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
             
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    *status = (double ) _main( msg );
    
    if ( nlhs == 2 ){
	if ( *status == 0 ){
	        plhs[1] = mxCreateString( msg );
		free( msg ); /* What is gonna happen ????) */
	} else {
		mwSize ts[] = {0};
		plhs[1] = mxCreateCellArray(0,ts);
	}
    }
    return;
}
